using System.Linq;
using app.tests.mocks;
using ebcpatterns.infrastructure;
using NUnit.Framework;

namespace app.tests
{
    [TestFixture]
    public class StructureMapComponentLoaderTests
    {
        private StructureMapComponentLoader sut;

        [SetUp]
        public void Setup() {
            sut = new StructureMapComponentLoader();
        }

        [Test]
        public void Integrationstest() {
            sut.Execute("x");

            var classWithDependency = (ClassWithDependency)sut.AllInstancesOfType<IDependsOn>().First();
            Assert.That(sut.AllInstancesOfType<IDependsOn>().Count(), Is.EqualTo(1));
            Assert.That(classWithDependency, Is.TypeOf<ClassWithDependency>());
            Assert.That(classWithDependency.Independend, Is.TypeOf<Independent>());

            var classThatNeedsConfiguration = (ClassThatNeedsConfiguration)sut.AllInstancesOfType<IConfigurable>().First();
            Assert.That(sut.AllInstancesOfType<IConfigurable>().Count(), Is.EqualTo(1));
            Assert.That(classThatNeedsConfiguration, Is.TypeOf<ClassThatNeedsConfiguration>());
            Assert.That(classThatNeedsConfiguration.Args, Is.EqualTo(new[]{"x"}));

            var classThatIsTheentryPoint = (ClassThatIsTheEntryPoint)sut.AllInstancesOfType<IEntryPoint>().First();
            Assert.That(sut.AllInstancesOfType<IEntryPoint>().Count(), Is.EqualTo(1));
            Assert.That(classThatIsTheentryPoint, Is.TypeOf<ClassThatIsTheEntryPoint>());
            Assert.That(classThatIsTheentryPoint.Args, Is.EqualTo(new[] { "x" }));
        }
    }
}